package com.ruoyi.base.exception;

import com.ruoyi.base.controller.BaseController;
import com.ruoyi.base.pojo.HttpResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author ruoyi
 */
@RestControllerAdvice
public class GlobalExceptionHandler extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 基础异常
     */
    @ExceptionHandler(Exception.class)
    public HttpResult<Exception> handleException(Exception e) {
        log.error(e.getMessage(), e);
        return new HttpResult<>(e);
    }

    /**
     * 业务异常
     */
    @ExceptionHandler(CustomException.class)
    public HttpResult<CustomException> businessException(CustomException e) {
        log.error(e.getMsg(), e);
        return new HttpResult<>(e);
    }
}
